home *** CD-ROM | disk | FTP | other *** search
- \ File comparison. Silent if the files are the same, messages if they
- \ are different.
- \
- \ Use: comparing file1 file2
-
- variable file1 variable file2
- : fcompare ( fd1 fd2 -- )
- file2 ! file1 !
- begin
- file1 @ fgetc file2 @ fgetc 2dup =
- while
- drop -1 = if exit then
- repeat ( char1 char2 )
- 2dup
- -1 = if ." End of file on file 2" drop 2drop exit then ( ch1 ch2 ch1)
- -1 = if ." End of file on file 1" 2drop exit then ( ch1 ch2 )
- decimal ." Files differ at position " file1 @ ftell l. cr
- hex swap ." File1: " . ." File2: " . cr
- ;
- : comparing \ file1 file2 ( -- )
- reading ifd @ reading ifd @ ( fd1 fd2 )
- 2dup fcompare
- close close
- ;
-